package util;

public class Pair<A, B> {
    private A first;

    private B second;

    public Pair(final A first, final B second) {
        super();
        this.first = first;
        this.second = second;
    }

    @Override
    public int hashCode() {
        // int hashFirst = this.first != null ? this.first.hashCode() : 0;
        int hashFirst = this.first == null ? 0 : this.first.hashCode();
        int hashSecond = this.second == null ? 0 : this.second.hashCode();

        return (hashFirst + hashSecond) * hashSecond + hashFirst;
    }

    @Override
    public boolean equals(final Object other) {
        if (other instanceof Pair) {
            Pair<?, ?> otherPair = (Pair<?, ?>) other;
            return (this.first == otherPair.first || this.first != null && otherPair.first != null
                    && this.first.equals(otherPair.first))
                    && (this.second == otherPair.second || this.second != null && otherPair.second != null
                            && this.second.equals(otherPair.second));
        }

        return false;
    }

    @Override
    public String toString() {
        return "(" + this.first + ", " + this.second + ")";
    }

    public A getFirst() {
        return this.first;
    }

    public void setFirst(final A first) {
        this.first = first;
    }

    public B getSecond() {
        return this.second;
    }

    public void setSecond(final B second) {
        this.second = second;
    }
}